package com.iflytek.cloud.thirdparty; import android.content.Context; import android.content.SharedPreferences; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.support.v4.app.NotificationCompat; import android.text.TextUtils; import android.util.Log; import cn.wps.shareplay.message.Message; import com.appsflyer.AppsFlyerProperties; import com.appsflyer.share.Constants; import com.baidu.tts.loopj.AsyncHttpResponseHandler; import com.google.firebase.perf.FirebasePerformance; import com.iflytek.cloud.SpeechConstant; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLEncoder; import java.text.SimpleDateFormat; import java.util.Date; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import org.apache.http.client.ClientProtocolException; import org.eclipse.paho.client.mqttv3.MqttTopic; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; /* renamed from: com.iflytek.cloud.thirdparty.b reason: case insensitive filesystem */ public class C0256b { public static boolean a = false; private static String b = "lxd"; private static int c = 1; private static boolean d = true; private static boolean e = false; private static boolean f = true; private static int g = 1; private static int h = 0; private static final String i = ("act" + b); private static final String j = ("evn" + b); private static final String k = ("esp" + b); private static final String l = (NotificationCompat.CATEGORY_ERROR + b); private static final String m = (NotificationCompat.CATEGORY_SYSTEM + b); private static String n = ""; private static long o = 0; private static String p = ""; private static Object q = new Object(); private static Object r = new Object(); private static Object s = new Object(); private static boolean t = false; private static boolean u = false; private static String v = ""; private static ExecutorService w = Executors.newSingleThreadExecutor(); /* JADX WARNING: Code restructure failed: missing block: B:27:0x015d, code lost: r2.disconnect(); r0 = 2; */ /* JADX WARNING: Code restructure failed: missing block: B:31:0x0171, code lost: r2.disconnect(); r0 = 2; */ /* JADX WARNING: Code restructure failed: missing block: B:35:0x0186, code lost: r2.disconnect(); r0 = 3; */ /* JADX WARNING: Code restructure failed: missing block: B:39:0x019b, code lost: r2.disconnect(); r0 = r1; */ /* JADX WARNING: Code restructure failed: missing block: B:45:0x01ab, code lost: r1 = move-exception; */ /* JADX WARNING: Code restructure failed: missing block: B:46:0x01ac, code lost: r2 = r0; r0 = r1; */ /* JADX WARNING: Code restructure failed: missing block: B:49:0x01b4, code lost: r1 = move-exception; */ /* JADX WARNING: Code restructure failed: missing block: B:50:0x01b5, code lost: r2 = r0; r0 = r1; r1 = 1; */ /* JADX WARNING: Code restructure failed: missing block: B:51:0x01b9, code lost: r1 = move-exception; */ /* JADX WARNING: Code restructure failed: missing block: B:52:0x01ba, code lost: r2 = r0; r0 = r1; */ /* JADX WARNING: Code restructure failed: missing block: B:53:0x01bd, code lost: r2 = move-exception; */ /* JADX WARNING: Code restructure failed: missing block: B:54:0x01be, code lost: r2 = r0; r0 = r2; */ /* JADX WARNING: Code restructure failed: missing block: B:55:0x01c2, code lost: r2 = move-exception; */ /* JADX WARNING: Code restructure failed: missing block: B:56:0x01c3, code lost: r2 = r0; r0 = r2; */ /* JADX WARNING: Failed to process nested try/catch */ /* JADX WARNING: Removed duplicated region for block: B:27:0x015d */ /* JADX WARNING: Removed duplicated region for block: B:31:0x0171 */ /* JADX WARNING: Removed duplicated region for block: B:35:0x0186 */ /* JADX WARNING: Removed duplicated region for block: B:39:0x019b */ /* JADX WARNING: Removed duplicated region for block: B:42:0x01a4 */ /* JADX WARNING: Removed duplicated region for block: B:45:0x01ab A[ExcHandler: all (r1v9 'th' java.lang.Throwable A[CUSTOM_DECLARE]), Splitter:B:7:0x0090] */ /* JADX WARNING: Removed duplicated region for block: B:51:0x01b9 A[ExcHandler: JSONException (r1v8 'e' org.json.JSONException A[CUSTOM_DECLARE]), PHI: r3 PHI: (r3v17 int) = (r3v0 int), (r3v19 int), (r3v19 int), (r3v19 int) binds: [B:7:0x0090, B:8:?, B:12:0x00ee, B:13:?] A[DONT_GENERATE, DONT_INLINE], Splitter:B:7:0x0090] */ /* JADX WARNING: Removed duplicated region for block: B:53:0x01bd A[ExcHandler: IOException (r2v28 'e' java.io.IOException A[CUSTOM_DECLARE]), PHI: r3 PHI: (r3v16 int) = (r3v0 int), (r3v19 int), (r3v19 int), (r3v19 int) binds: [B:7:0x0090, B:8:?, B:12:0x00ee, B:13:?] A[DONT_GENERATE, DONT_INLINE], Splitter:B:7:0x0090] */ /* JADX WARNING: Removed duplicated region for block: B:55:0x01c2 A[ExcHandler: ClientProtocolException (r2v26 'e' org.apache.http.client.ClientProtocolException A[CUSTOM_DECLARE]), PHI: r3 PHI: (r3v15 int) = (r3v0 int), (r3v19 int), (r3v19 int), (r3v19 int) binds: [B:7:0x0090, B:8:?, B:12:0x00ee, B:13:?] A[DONT_GENERATE, DONT_INLINE], Splitter:B:7:0x0090] */ private static int a(Context context, String str, JSONObject jSONObject) { Exception e2; int i2 = 0; int i3 = 2; if (c != 1) { return 2; } C0257c.a("MobileAgentRun", "run into httppost :" + str + "####" + context.getClass().getName() + "###" + jSONObject.toString()); HttpURLConnection httpURLConnection = null; try { C0257c.a("MobileAgentRun", jSONObject.toString()); C0257c.a("MobileAgentRun", "post start"); HttpURLConnection httpURLConnection2 = (HttpURLConnection) new URL(String.valueOf(str) + "&appkey=" + C0262h.h(context) + "&channel=" + URLEncoder.encode(C0262h.i(context), AsyncHttpResponseHandler.DEFAULT_CHARSET) + "&code=106").openConnection(); try { httpURLConnection2.setReadTimeout(10000); httpURLConnection2.setDoOutput(true); httpURLConnection2.setDoInput(true); httpURLConnection2.setUseCaches(false); httpURLConnection2.setRequestMethod(FirebasePerformance.HttpMethod.POST); byte[] a2 = C0261g.a().a(jSONObject.toString()); httpURLConnection2.setRequestProperty("Content-length", new StringBuilder().append(a2.length).toString()); httpURLConnection2.setRequestProperty("Content-Type", "application/octet-stream"); httpURLConnection2.setRequestProperty("Charset", AsyncHttpResponseHandler.DEFAULT_CHARSET); OutputStream outputStream = httpURLConnection2.getOutputStream(); outputStream.write(a2); outputStream.close(); i2 = httpURLConnection2.getResponseCode(); C0257c.a("MobileAgentRun", "post end"); if (200 == i2) { C0257c.a("MobileAgent", "send success"); i3 = 1; } if (httpURLConnection2 != null) { httpURLConnection2.disconnect(); } } catch (ClientProtocolException e3) { } catch (IOException e4) { } catch (JSONException e5) { } catch (Exception e6) { httpURLConnection = httpURLConnection2; e2 = e6; C0257c.a("MobileAgentRun", e2.toString()); e2.printStackTrace(); if (httpURLConnection != null) { } int i4 = i3; C0257c.a("MobileAgentHttpPost", "code:" + i2 + "status: " + i4 + " content: " + jSONObject.getString("logJsonAry")); C0257c.a("MobileAgentRun", "run out httppost :" + context.getClass().getName() + " resultcode:" + i4); return i4; } catch (Throwable th) { } } catch (ClientProtocolException e7) { ClientProtocolException e8 = e7; try { C0257c.a("MobileAgentRun", e8.toString()); e8.printStackTrace(); if (httpURLConnection != null) { } int i42 = i3; C0257c.a("MobileAgentHttpPost", "code:" + i2 + "status: " + i42 + " content: " + jSONObject.getString("logJsonAry")); C0257c.a("MobileAgentRun", "run out httppost :" + context.getClass().getName() + " resultcode:" + i42); return i42; } catch (Throwable th2) { Throwable th3 = th2; if (httpURLConnection != null) { httpURLConnection.disconnect(); } throw th3; } } catch (IOException e9) { IOException e10 = e9; C0257c.a("MobileAgentRun", e10.toString()); e10.printStackTrace(); if (httpURLConnection != null) { } int i422 = i3; C0257c.a("MobileAgentHttpPost", "code:" + i2 + "status: " + i422 + " content: " + jSONObject.getString("logJsonAry")); C0257c.a("MobileAgentRun", "run out httppost :" + context.getClass().getName() + " resultcode:" + i422); return i422; } catch (JSONException e11) { JSONException e12 = e11; C0257c.a("MobileAgentRun", e12.toString()); e12.printStackTrace(); i3 = 3; if (httpURLConnection != null) { } int i4222 = i3; C0257c.a("MobileAgentHttpPost", "code:" + i2 + "status: " + i4222 + " content: " + jSONObject.getString("logJsonAry")); C0257c.a("MobileAgentRun", "run out httppost :" + context.getClass().getName() + " resultcode:" + i4222); return i4222; } catch (Exception e13) { e2 = e13; C0257c.a("MobileAgentRun", e2.toString()); e2.printStackTrace(); if (httpURLConnection != null) { } int i42222 = i3; C0257c.a("MobileAgentHttpPost", "code:" + i2 + "status: " + i42222 + " content: " + jSONObject.getString("logJsonAry")); C0257c.a("MobileAgentRun", "run out httppost :" + context.getClass().getName() + " resultcode:" + i42222); return i42222; } int i422222 = i3; try { C0257c.a("MobileAgentHttpPost", "code:" + i2 + "status: " + i422222 + " content: " + jSONObject.getString("logJsonAry")); } catch (Exception e14) { } C0257c.a("MobileAgentRun", "run out httppost :" + context.getClass().getName() + " resultcode:" + i422222); return i422222; } protected static SharedPreferences a(Context context) { return context.getSharedPreferences(String.valueOf(b) + "MoblieAgent_event_" + context.getPackageName(), 0); } private static String a(Context context, String str, SharedPreferences sharedPreferences) { long j2 = 0; n = ""; String a2 = C0262h.a(context, str); SharedPreferences.Editor edit = sharedPreferences.edit(); edit.putString("appKey", str); edit.putString("sessionId", a2); edit.putLong("lastResumeTime", System.currentTimeMillis()); edit.putString("activities", i(context, "onResume", null)); long j3 = sharedPreferences.getLong("readFlowRev", 0); long[] o2 = C0262h.o(context); edit.putLong("readFlowRev", o2[0]); long j4 = o2[0] - j3; if (j4 < 0) { j4 = 0; } edit.putLong("consumeFlowRev", j4); long j5 = sharedPreferences.getLong("readFlowSnd", 0); edit.putLong("readFlowSnd", o2[1]); long j6 = o2[1] - j5; if (j6 >= 0) { j2 = j6; } edit.putLong("consumeFlowSnd", j2); edit.commit(); p = a2; return a2; } private static void a(Context context, String str, long j2) { synchronized (q) { SharedPreferences c2 = c(context); int i2 = c2.getInt("uploadcount", 0); String str2 = String.valueOf(c2.getString("uploadList", "")) + str + "|"; if (j2 > 10000) { j2 = 1; } c2.edit().putString("uploadList", str2).commit(); c2.edit().putLong("uploadpopindex", j2).commit(); if (str2.split("\\|").length > 30000) { String n2 = n(context); context.deleteFile(n2); j(context, n2); } else { c2.edit().putInt("uploadcount", i2 + 1).commit(); } } } public static void a(Context context, String str, String str2) { if (c == 0) { Log.i("MobileAgent", "Du have not permission to collect data"); } else if (str.contains(MqttTopic.MULTI_LEVEL_WILDCARD)) { Log.w("MobileAgent", "the eventId contain illegal char"); } else { h(context, str, str2); } } protected static void a(Context context, boolean z) { if (z) { C0257c.a("MobileAgentRun", "run into pageact onresumep"); h(context); } else { C0257c.a("MobileAgentRun", "run into pageact onpausep"); i(context); } C0257c.a("MobileAgentRun", "run out pageact"); } protected static boolean a(Context context, int i2) { int i3; int i4; SharedPreferences k2 = k(context); if (i2 == 3) { i3 = k2.getInt("actionmonth", 0); i4 = k2.getInt("actionday", 0); } else if (i2 == 2) { i3 = k2.getInt("eventmonth", 0); i4 = k2.getInt("eventday", 0); } else { i3 = k2.getInt("sysmonth", 0); i4 = k2.getInt("sysday", 0); } Date date = new Date(); return (Integer.valueOf(new SimpleDateFormat("M").format(date)).intValue() == i3 && Integer.valueOf(new SimpleDateFormat("dd").format(date)).intValue() == i4) ? false : true; } private static boolean a(Context context, SharedPreferences sharedPreferences) { SharedPreferences a2 = a(context); String string = a2.getString("eventlogs", ""); if (string.equals("")) { return false; } String string2 = l(context).getString("sessionId", null); JSONObject jSONObject = new JSONObject(); try { jSONObject.put(SpeechConstant.IST_SESSION_ID, string2); jSONObject.put("logJsonAry", string); if (a(context, jSONObject.toString(), 2)) { a2.edit().putString("eventlogs", "").commit(); } } catch (JSONException e2) { e2.printStackTrace(); } return true; } private static boolean a(Context context, SharedPreferences sharedPreferences, boolean z) { String string = sharedPreferences.getString("sessionId", ""); String string2 = sharedPreferences.getString("activities", ""); JSONObject jSONObject = new JSONObject(); try { jSONObject.put(SpeechConstant.IST_SESSION_ID, string); jSONObject.put("logs", string2); if (z) { jSONObject.put("flowConsumpRev", sharedPreferences.getLong("consumeFlowRev", 0)); jSONObject.put("flowConsumpSnd", sharedPreferences.getLong("consumeFlowSnd", 0)); } else { jSONObject.put("flowConsumpRev", 0); jSONObject.put("flowConsumpSnd", 0); } if (!a(context, jSONObject.toString(), 3)) { return true; } sharedPreferences.edit().putString("activities", "").commit(); return true; } catch (JSONException e2) { e2.printStackTrace(); return true; } } protected static boolean a(Context context, String str) { int i2; String h2 = h(context, str); if (!h2.equals("")) { JSONObject d2 = d(context); try { try { d2.put(SpeechConstant.IST_SESSION_ID, new JSONObject(h2).get(SpeechConstant.IST_SESSION_ID)); } catch (JSONException e2) { d2.put(SpeechConstant.IST_SESSION_ID, ""); } d2.put("mac", C0262h.g(context)); try { d2.put("deviceDetail", URLEncoder.encode(C0262h.a(), AsyncHttpResponseHandler.DEFAULT_CHARSET)); } catch (UnsupportedEncodingException e3) { d2.put("deviceDetail", ""); } try { d2.put("manufacturer", URLEncoder.encode(C0262h.b(), AsyncHttpResponseHandler.DEFAULT_CHARSET)); } catch (UnsupportedEncodingException e4) { d2.put("manufacturer", ""); } try { d2.put("phoneOs", URLEncoder.encode(C0262h.c(), AsyncHttpResponseHandler.DEFAULT_CHARSET)); } catch (UnsupportedEncodingException e5) { d2.put("phoneOs", ""); } try { d2.put("accessPoint", URLEncoder.encode(C0262h.l(context), AsyncHttpResponseHandler.DEFAULT_CHARSET)); } catch (UnsupportedEncodingException e6) { d2.put("accessPoint", ""); } try { d2.put("netWorkType", URLEncoder.encode(C0262h.p(context), AsyncHttpResponseHandler.DEFAULT_CHARSET)); } catch (UnsupportedEncodingException e7) { d2.put("netWorkType", ""); } d2.put("uuid", v); d2.put("deviceId", C0262h.a(context)); d2.put("cpuRatioMax", C0262h.f()); d2.put("cpuRatioCur", C0262h.g()); d2.put("menoryRatio", C0262h.h()); d2.put("logJsonAry", new JSONArray("[" + h2 + "]")); i2 = a(context, "http://da.mmarket.com/mmsdk/mmsdk?func=mmsdk:postactlog", d2); } catch (JSONException e8) { e8.printStackTrace(); i2 = 3; } if (i2 == 1 || i2 == 3) { b(context, 3); i(context, str); Log.i("MobileAgent", "act log sd"); return true; } if (i2 == 2) { } return false; } b(context, 3); i(context, str); return true; } /* JADX WARNING: Code restructure failed: missing block: B:38:?, code lost: r1.close(); */ /* JADX WARNING: Code restructure failed: missing block: B:39:0x006c, code lost: r1 = move-exception; */ /* JADX WARNING: Code restructure failed: missing block: B:40:0x006d, code lost: r1.printStackTrace(); */ /* JADX WARNING: Code restructure failed: missing block: B:47:?, code lost: android.util.Log.w("MobileAgentRun", "file r/w execption"); */ /* JADX WARNING: Code restructure failed: missing block: B:48:0x007c, code lost: if (0 != 0) goto L_0x007e; */ /* JADX WARNING: Code restructure failed: missing block: B:50:?, code lost: r2.close(); */ /* JADX WARNING: Code restructure failed: missing block: B:51:0x0082, code lost: r0 = move-exception; */ /* JADX WARNING: Code restructure failed: missing block: B:52:0x0083, code lost: r0.printStackTrace(); */ /* JADX WARNING: Code restructure failed: missing block: B:53:0x0087, code lost: r0 = th; */ /* JADX WARNING: Code restructure failed: missing block: B:65:0x009c, code lost: r1 = r2; */ /* JADX WARNING: Failed to process nested try/catch */ /* JADX WARNING: Removed duplicated region for block: B:37:0x0068 A[SYNTHETIC, Splitter:B:37:0x0068] */ /* JADX WARNING: Removed duplicated region for block: B:44:0x0074 A[ExcHandler: IOException (e java.io.IOException), Splitter:B:10:0x0030] */ /* JADX WARNING: Removed duplicated region for block: B:55:0x008a A[SYNTHETIC, Splitter:B:55:0x008a] */ private static synchronized boolean a(Context context, String str, int i2) { String str2; boolean z = false; synchronized (C0256b.class) { if (i2 == 3) { str2 = i; } else if (i2 == 2) { str2 = j; } else if (i2 == 4) { str2 = l; } else if (i2 == 1) { str2 = m; } else if (i2 == 5) { str2 = k; } if (!str.trim().equals("")) { long m2 = m(context); long j2 = 1 + m2; String str3 = String.valueOf(str2) + m2; FileOutputStream fileOutputStream = null; try { FileOutputStream openFileOutput = context.openFileOutput(str3, 1); a(context, str3, j2); openFileOutput.write(str.getBytes()); if (openFileOutput != null) { try { openFileOutput.close(); } catch (IOException e2) { e2.printStackTrace(); } } } catch (FileNotFoundException e3) { FileOutputStream fileOutputStream2 = null; try { Log.w("MobileAgentRun", "can not find log file"); if (fileOutputStream2 != null) { } return z; } catch (Throwable th) { Throwable th2 = th; fileOutputStream = fileOutputStream2; if (fileOutputStream != null) { try { fileOutputStream.close(); } catch (IOException e4) { e4.printStackTrace(); } } throw th2; } } catch (IOException e5) { } z = true; } } return z; } private static boolean a(SharedPreferences sharedPreferences) { return System.currentTimeMillis() - sharedPreferences.getLong("endTime", -1) > 30000; } protected static SharedPreferences b(Context context) { return context.getSharedPreferences(String.valueOf(b) + "MoblieAgent_event_sp" + context.getPackageName(), 0); } protected static void b(Context context, int i2) { Date date = new Date(); int parseInt = Integer.parseInt(new SimpleDateFormat("dd").format(date)); int parseInt2 = Integer.parseInt(new SimpleDateFormat("M").format(date)); SharedPreferences.Editor edit = k(context).edit(); if (i2 == 3) { edit.putInt("actionmonth", parseInt2); edit.putInt("actionday", parseInt); } else if (i2 == 2) { edit.putInt("eventmonth", parseInt2); edit.putInt("eventday", parseInt); } else { edit.putInt("sysmonth", parseInt2); edit.putInt("sysday", parseInt); } edit.commit(); } protected static void b(Context context, String str, String str2) { synchronized (r) { String a2 = C0262h.a(str); String a3 = C0262h.a(str2); SharedPreferences a4 = a(context); StringBuffer stringBuffer = new StringBuffer(); stringBuffer.append(a4.getString("eventlogs", "")); try { stringBuffer.append(URLEncoder.encode(a2, AsyncHttpResponseHandler.DEFAULT_CHARSET)); stringBuffer.append("|"); stringBuffer.append(URLEncoder.encode(a3, AsyncHttpResponseHandler.DEFAULT_CHARSET)); stringBuffer.append("|"); stringBuffer.append(1); stringBuffer.append("|"); stringBuffer.append(System.currentTimeMillis()); stringBuffer.append("\n"); a4.edit().putString("eventlogs", stringBuffer.toString()).commit(); a(context, (SharedPreferences) null); } catch (UnsupportedEncodingException e2) { C0257c.a("MobileAgentRun", "unsupport utf-8,can't onEvent()"); return; } } b(context, false); } protected static void b(Context context, boolean z) { if (c == 1) { C0257c.a("MobileAgentRun", "run into strategy"); f(context); if (!e || (e && o(context))) { switch (g) { case 1: new C0258d(context, 6).start(); break; case 2: if (z) { new C0258d(context, 6).start(); f = false; break; } break; case 3: if (a(context, 3)) { new C0258d(context, 6).start(); break; } break; } } f = false; C0257c.a("MobileAgentRun", "run out strategy"); } } private static boolean b(Context context, SharedPreferences sharedPreferences) { SharedPreferences b2 = b(context); String string = b2.getString("eventlogs", ""); if (string.equals("")) { return false; } String string2 = l(context).getString("sessionId", null); JSONObject jSONObject = new JSONObject(); try { jSONObject.put(SpeechConstant.IST_SESSION_ID, string2); jSONObject.put("logJsonAry", string); if (a(context, jSONObject.toString(), 5)) { b2.edit().putString("eventlogs", "").commit(); } } catch (JSONException e2) { e2.printStackTrace(); } return true; } protected static boolean b(Context context, String str) { try { if (a(context, "http://da.mmarket.com/mmsdk/mmsdk?func=mmsdk:postsyslog", new JSONObject(h(context, str))) == 1) { i(context, str); return true; } } catch (JSONException e2) { i(context, str); Log.i("MobileAgent", "SDK del a dirty data"); } return false; } protected static SharedPreferences c(Context context) { return context.getSharedPreferences(String.valueOf(b) + "MoblieAgent_upload_" + context.getPackageName(), 0); } protected static void c(Context context, String str, String str2) { synchronized (s) { String a2 = C0262h.a(str); String a3 = C0262h.a(str2); SharedPreferences b2 = b(context); StringBuffer stringBuffer = new StringBuffer(); stringBuffer.append(b2.getString("eventlogs", "")); try { stringBuffer.append(URLEncoder.encode(a2, AsyncHttpResponseHandler.DEFAULT_CHARSET)); stringBuffer.append("|"); stringBuffer.append(URLEncoder.encode(a3, AsyncHttpResponseHandler.DEFAULT_CHARSET)); stringBuffer.append("|"); stringBuffer.append(1); stringBuffer.append("|"); stringBuffer.append(System.currentTimeMillis()); stringBuffer.append("\n"); b2.edit().putString("eventlogs", stringBuffer.toString()).commit(); if (g == 1 || stringBuffer.toString().getBytes().length > 10000) { b(context, (SharedPreferences) null); } } catch (UnsupportedEncodingException e2) { C0257c.a("MobileAgent", "unsupport utf-8,can't onEvent()"); return; } } b(context, false); } protected static boolean c(Context context, String str) { String h2 = h(context, str); try { JSONObject jSONObject = new JSONObject(h2); jSONObject.put(Constants.URL_MEDIA_SOURCE, 1); jSONObject.put("protocolVersion", "3.1.4"); jSONObject.put("sdkVersion", "3.2.0.2"); jSONObject.put("cid", C0262h.b(context)); jSONObject.put("deviceId", C0262h.a(context)); jSONObject.put("appKey", C0262h.h(context)); jSONObject.put("packageName", C0262h.j(context)); jSONObject.put("versionCode", C0262h.m(context)); jSONObject.put("versionName", C0262h.n(context)); jSONObject.put("sendTime", System.currentTimeMillis()); int a2 = a(context, "http://da.mmarket.com/mmsdk/mmsdk?func=mmsdk:posterrlog", jSONObject); if (a2 == 1 || a2 == 3) { b(context, 3); i(context, str); Log.i("MobileAgent", "erLog sd"); C0257c.a("MobileAgent", "send errlog success \n" + h2); return true; } if (a2 == 2) { } return false; } catch (JSONException e2) { i(context, str); Log.i("MobileAgent", "SDK del a dirty data"); return false; } } protected static JSONObject d(Context context) { JSONObject jSONObject = new JSONObject(); try { jSONObject.put(Constants.URL_MEDIA_SOURCE, 1); jSONObject.put("protocolVersion", "3.1.4"); jSONObject.put("sdkVersion", "3.2.0.2"); jSONObject.put("cid", C0262h.b(context)); jSONObject.put("appKey", C0262h.h(context)); jSONObject.put("packageName", context.getPackageName()); jSONObject.put("versionCode", C0262h.m(context)); jSONObject.put("versionName", C0262h.n(context)); jSONObject.put("sendTime", System.currentTimeMillis()); jSONObject.put("deviceId", C0262h.a(context)); jSONObject.put(AppsFlyerProperties.CHANNEL, C0262h.i(context)); } catch (JSONException e2) { e2.printStackTrace(); } return jSONObject; } protected static void d(Context context, String str) { k(context).edit().putString(str, "record").commit(); } public static void d(Context context, String str, String str2) { if (t) { Log.i("MobileAgent", "already init"); return; } try { if (!a) { a = !context.getSharedPreferences("MoblieAgent_debug", 0).getString("debug", "").equals(""); } } catch (Exception e2) { } C0257c.a("MobileAgentAPI", "run in init[" + str + Message.SEPARATE + str2 + "]"); if (context == null) { Log.e("MobileAgent", "Exception occurent in joinDu ,context cann't be null"); } else if (TextUtils.isEmpty(str) || C0262h.a(str, 50)) { Log.e("MobileAgent", "Exception occurent in joinDu ,appID cann't be null or empty"); } else { if (TextUtils.isEmpty(str2)) { str2 = "0"; } else if (C0262h.a(str2, 100)) { str2 = str2.substring(0, 99); Log.e("MobileAgent", "Exception occurent in joinDu ,channelID cann't be null or empty"); } SharedPreferences sharedPreferences = context.getSharedPreferences(String.valueOf(b) + "MoblieAgent_sys_config", 0); sharedPreferences.edit().putString("MOBILE_APPKEY", str).commit(); sharedPreferences.edit().putString("MOBILE_CHANNEL", str2).commit(); if (!e(context, "#lxapkmd5")) { new Thread(new RunnableC0260f(context)).start(); } t = true; Log.i("MobileAgent", "finish init SUCCESS " + a); } } protected static void e(Context context) { JSONObject jSONObject = new JSONObject(); try { jSONObject.put(Constants.URL_MEDIA_SOURCE, 1); jSONObject.put("protocolVersion", "3.1.4"); jSONObject.put("sdkVersion", "3.2.0.2"); jSONObject.put("cid", C0262h.b(context)); jSONObject.put("deviceId", C0262h.a(context)); jSONObject.put("appKey", C0262h.h(context)); jSONObject.put("packageName", context.getPackageName()); jSONObject.put("versionCode", C0262h.m(context)); jSONObject.put("versionName", C0262h.n(context)); jSONObject.put("sendTime", System.currentTimeMillis()); jSONObject.put("imsi", C0262h.c(context)); jSONObject.put("mac", C0262h.g(context)); jSONObject.put("deviceDetail", URLEncoder.encode(C0262h.a(), AsyncHttpResponseHandler.DEFAULT_CHARSET)); jSONObject.put("manufacturer", URLEncoder.encode(C0262h.b(), AsyncHttpResponseHandler.DEFAULT_CHARSET)); jSONObject.put("phoneOS", URLEncoder.encode(C0262h.c(), AsyncHttpResponseHandler.DEFAULT_CHARSET)); jSONObject.put("screenWidth", C0262h.d(context)); jSONObject.put("screenHeight", C0262h.e(context)); jSONObject.put("screenDensity", C0262h.f(context)); jSONObject.put("carrierName", URLEncoder.encode(C0262h.k(context), AsyncHttpResponseHandler.DEFAULT_CHARSET)); jSONObject.put("accessPoint", C0262h.l(context)); jSONObject.put("countryCode", C0262h.d()); jSONObject.put("languageCode", C0262h.e()); jSONObject.put(AppsFlyerProperties.CHANNEL, URLEncoder.encode(C0262h.i(context), AsyncHttpResponseHandler.DEFAULT_CHARSET)); if (a(context, jSONObject.toString(), 1)) { b(context, 1); } } catch (JSONException e2) { e2.printStackTrace(); } catch (UnsupportedEncodingException e3) { e3.printStackTrace(); } } protected static boolean e(Context context, String str) { return !k(context).getString(str, "").equals(""); } protected static boolean e(Context context, String str, String str2) { String h2 = str2 == null ? h(context, str) : str2; if (!h2.equals("")) { try { JSONObject jSONObject = new JSONObject(h2); String b2 = C0262h.b(context); jSONObject.put(Constants.URL_MEDIA_SOURCE, 1); jSONObject.put("protocolVersion", "3.1.4"); jSONObject.put("sdkVersion", "3.2.0.2"); jSONObject.put("cid", b2); jSONObject.put("appKey", C0262h.h(context)); jSONObject.put("packageName", C0262h.j(context)); jSONObject.put("versionCode", C0262h.m(context)); jSONObject.put("versionName", C0262h.n(context)); jSONObject.put("sendTime", System.currentTimeMillis()); jSONObject.put("mac", C0262h.g(context)); try { jSONObject.put("deviceDetail", URLEncoder.encode(C0262h.a(), AsyncHttpResponseHandler.DEFAULT_CHARSET)); } catch (UnsupportedEncodingException e2) { jSONObject.put("deviceDetail", ""); } try { jSONObject.put("manufacturer", URLEncoder.encode(C0262h.b(), AsyncHttpResponseHandler.DEFAULT_CHARSET)); } catch (UnsupportedEncodingException e3) { jSONObject.put("manufacturer", ""); } try { jSONObject.put("phoneOs", URLEncoder.encode(C0262h.c(), AsyncHttpResponseHandler.DEFAULT_CHARSET)); } catch (UnsupportedEncodingException e4) { jSONObject.put("phoneOs", ""); } jSONObject.put("accessPoint", C0262h.l(context)); jSONObject.put("deviceId", C0262h.a(context)); try { jSONObject.put(AppsFlyerProperties.CHANNEL, URLEncoder.encode(C0262h.i(context), AsyncHttpResponseHandler.DEFAULT_CHARSET)); } catch (UnsupportedEncodingException e5) { jSONObject.put(AppsFlyerProperties.CHANNEL, ""); } int a2 = a(context, "http://da.mmarket.com/mmsdk/mmsdk?func=mmsdk:posteventlog", jSONObject); if (a2 == 1 || a2 == 3) { if (str2 == null) { b(context, 3); i(context, str); Log.i("MobileAgent", "evn log sd"); } else { Log.i("MobileAgent", "evnrt log sd"); } return true; } else if (a2 != 2) { return false; } else { Log.w("MobileAgent", "please check your network"); return false; } } catch (JSONException e6) { i(context, str); e6.printStackTrace(); return true; } } else if (str2 != null) { return false; } else { b(context, 3); i(context, str); return true; } } protected static void f(Context context) { if (f) { if (g(context, "updateonlyonwifi").equals("1")) { e = true; } else { e = false; } String g2 = g(context, "updatedelay"); if (!g2.equals("0")) { h = Integer.parseInt(g2) * 1000; } int parseInt = Integer.parseInt(g(context, "send_policy")); g = parseInt; if (parseInt == 0) { g = 1; } } } protected static void f(Context context, String str) { if (!str.trim().equals("")) { try { JSONObject jSONObject = new JSONObject(); JSONArray jSONArray = new JSONArray(); JSONObject jSONObject2 = new JSONObject(); jSONObject2.put("occurtime", System.currentTimeMillis()); jSONObject2.put("errmsg", URLEncoder.encode(str, AsyncHttpResponseHandler.DEFAULT_CHARSET)); jSONArray.put(jSONObject2); jSONObject.put(SpeechConstant.IST_SESSION_ID, p); jSONObject.put("errjsonary", jSONArray); C0257c.a("MobileAgentRun", "errJso" + jSONObject.toString()); a(context, jSONObject.toString(), 4); } catch (JSONException e2) { C0257c.a("MobileAgentRun", "json exception,lost catch Exception"); } catch (UnsupportedEncodingException e3) { C0257c.a("MobileAgentRun", "unsupport utf-8,lost catch Exception"); } } } protected static boolean f(Context context, String str, String str2) { String h2 = str2 == null ? h(context, str) : str2; if (!h2.equals("")) { boolean z = h2.contains("%23lxapkmd5"); try { JSONObject jSONObject = new JSONObject(h2); String b2 = C0262h.b(context); jSONObject.put(Constants.URL_MEDIA_SOURCE, 1); jSONObject.put("protocolVersion", "3.1.4"); jSONObject.put("sdkVersion", "3.2.0.2"); jSONObject.put("cid", b2); jSONObject.put("appKey", C0262h.h(context)); jSONObject.put("packageName", C0262h.j(context)); jSONObject.put("versionCode", C0262h.m(context)); jSONObject.put("versionName", C0262h.n(context)); jSONObject.put("sendTime", System.currentTimeMillis()); jSONObject.put("mac", C0262h.g(context)); try { jSONObject.put("deviceDetail", URLEncoder.encode(C0262h.a(), AsyncHttpResponseHandler.DEFAULT_CHARSET)); } catch (UnsupportedEncodingException e2) { jSONObject.put("deviceDetail", ""); } try { jSONObject.put("manufacturer", URLEncoder.encode(C0262h.b(), AsyncHttpResponseHandler.DEFAULT_CHARSET)); } catch (UnsupportedEncodingException e3) { jSONObject.put("manufacturer", ""); } try { jSONObject.put("phoneOs", URLEncoder.encode(C0262h.c(), AsyncHttpResponseHandler.DEFAULT_CHARSET)); } catch (UnsupportedEncodingException e4) { jSONObject.put("phoneOs", ""); } jSONObject.put("accessPoint", C0262h.l(context)); jSONObject.put("deviceId", C0262h.a(context)); try { jSONObject.put(AppsFlyerProperties.CHANNEL, URLEncoder.encode(C0262h.i(context), AsyncHttpResponseHandler.DEFAULT_CHARSET)); } catch (UnsupportedEncodingException e5) { jSONObject.put(AppsFlyerProperties.CHANNEL, ""); } int a2 = a(context, "http://da.mmarket.com/mmsdk/mmsdk?func=mmsdk:specposteventlog", jSONObject); if (a2 == 1 || a2 == 3) { if (str2 == null) { b(context, 3); i(context, str); Log.i("MobileAgent", "evn log sd"); } else { Log.i("MobileAgent", "evnrt log sd"); } if (z && a2 == 1) { d(context, "#lxapkmd5"); } return true; } else if (a2 != 2) { return false; } else { Log.w("MobileAgent", "please check your network"); return false; } } catch (JSONException e6) { i(context, str); e6.printStackTrace(); return true; } } else if (str2 != null) { return false; } else { b(context, 3); i(context, str); return true; } } private static String g(Context context, String str) { return k(context).getString(str, "0"); } static synchronized void g(Context context) { synchronized (C0256b.class) { C0257c.a("MobileAgentRun", "run into uploadlist :" + context.getClass().getName()); if (g == 2) { try { Thread.sleep((long) h); } catch (InterruptedException e2) { e2.printStackTrace(); } } boolean z = true; System.currentTimeMillis(); while (true) { String n2 = n(context); if (n2.equals("") || !z) { C0257c.a("MobileAgentRun", " finish uploadlist "); C0257c.a("MobileAgentRun", "run out uploadlist :" + context.getClass().getName()); } else { if (n2.substring(0, 6).equals(i)) { z = a(context, n2); } else if (n2.substring(0, 6).equals(j)) { z = e(context, n2, null); } else if (n2.substring(0, 6).equals(l)) { z = c(context, n2); } else if (n2.substring(0, 6).equals(m)) { z = b(context, n2); } else if (n2.substring(0, 6).equals(k)) { z = f(context, n2, null); } if (z) { try { Thread.sleep(0); } catch (InterruptedException e3) { e3.printStackTrace(); } } C0257c.a("MobileAgentRun", "finish a task : " + n2); } } C0257c.a("MobileAgentRun", " finish uploadlist "); C0257c.a("MobileAgentRun", "run out uploadlist :" + context.getClass().getName()); } } /* JADX WARNING: Removed duplicated region for block: B:24:0x003e A[SYNTHETIC, Splitter:B:24:0x003e] */ /* JADX WARNING: Removed duplicated region for block: B:32:0x0053 A[SYNTHETIC, Splitter:B:32:0x0053] */ /* JADX WARNING: Removed duplicated region for block: B:39:0x0060 A[SYNTHETIC, Splitter:B:39:0x0060] */ private static synchronized String h(Context context, String str) { FileInputStream fileInputStream; Throwable th; IOException e2; String str2; FileNotFoundException e3; synchronized (C0256b.class) { try { fileInputStream = context.openFileInput(str); try { byte[] bArr = new byte[10000]; str2 = ""; while (true) { try { int read = fileInputStream.read(bArr); if (read == -1) { break; } str2 = String.valueOf(str2) + new String(bArr, 0, read); } catch (FileNotFoundException e4) { e3 = e4; try { e3.printStackTrace(); if (fileInputStream != null) { } return str2; } catch (Throwable th2) { th = th2; if (fileInputStream != null) { } throw th; } } catch (IOException e5) { e2 = e5; e2.printStackTrace(); if (fileInputStream != null) { } return str2; } } if (fileInputStream != null) { try { fileInputStream.close(); } catch (IOException e6) { e6.printStackTrace(); } } } catch (FileNotFoundException e7) { e3 = e7; str2 = ""; e3.printStackTrace(); if (fileInputStream != null) { } return str2; } catch (IOException e8) { e2 = e8; str2 = ""; e2.printStackTrace(); if (fileInputStream != null) { } return str2; } } catch (FileNotFoundException e9) { fileInputStream = null; e3 = e9; str2 = ""; e3.printStackTrace(); if (fileInputStream != null) { try { fileInputStream.close(); } catch (IOException e10) { e10.printStackTrace(); } } return str2; } catch (IOException e11) { fileInputStream = null; e2 = e11; str2 = ""; e2.printStackTrace(); if (fileInputStream != null) { try { fileInputStream.close(); } catch (IOException e12) { e12.printStackTrace(); } } return str2; } catch (Throwable th3) { th = th3; fileInputStream = null; if (fileInputStream != null) { try { fileInputStream.close(); } catch (IOException e13) { e13.printStackTrace(); } } throw th; } } return str2; } private static void h(Context context) { C0257c.a("MobileAgentRun", "run into onresumep :" + context.getClass().getName()); try { C0257c.a("page pro", "do resume start: " + context.getClass().getName()); b(context, j(context)); } catch (Exception e2) { e2.printStackTrace(); } C0257c.a("MobileAgentRun", "run out onresume :" + context.getClass().getName()); } /* access modifiers changed from: private */ public static void h(Context context, String str, String str2) { C0257c.a("MobileAgentAPI", "run in onEvent [" + str + Message.SEPARATE + str2 + "]"); if (context == null) { Log.e("MobileAgent", "Exception occurent in onEvent ,context cann't be null"); return; } if (TextUtils.isEmpty(str) || C0262h.a(str, 100)) { Log.e("MobileAgent", "Exception occurent in onEvent ,channelID cann't be empty or length more than 100"); } if (C0262h.a(str2, 900)) { Log.e("MobileAgent", "Exception occurent in onEvent ,channelID cann't be empty or length more than 100"); } new C0258d(context, 11, str, str2).start(); } private static String i(Context context, String str, String str2) { long j2 = 0; long currentTimeMillis = System.currentTimeMillis(); if (str.equals("onResume")) { o = currentTimeMillis; } else if (str.equals("onPause") && n.equals(context.getClass().getName())) { long j3 = currentTimeMillis - o; if (j3 > 12000000) { j2 = 300000; } else if (j3 >= 0) { j2 = j3; } } if (str2 == null) { str2 = ""; } StringBuffer stringBuffer = new StringBuffer(); stringBuffer.append(str2); stringBuffer.append(str); stringBuffer.append("|"); stringBuffer.append(context.getClass().getName()); stringBuffer.append("|"); stringBuffer.append(currentTimeMillis); stringBuffer.append("|"); stringBuffer.append(j2); stringBuffer.append("|"); stringBuffer.append(n); stringBuffer.append("\n"); n = context.getClass().getName(); return stringBuffer.toString(); } private static void i(Context context) { C0257c.a("MobileAgentRun", "run into onpausep :" + context.getClass().getName()); SharedPreferences l2 = l(context); String string = l2.getString("activities", null); SharedPreferences.Editor edit = l2.edit(); edit.putLong("endTime", System.currentTimeMillis()); edit.putString("activities", i(context, "onPause", string)); edit.commit(); C0257c.a("MobileAgentRun", "run out onpausep :" + context.getClass().getName()); } private static void i(Context context, String str) { if (str != null) { context.deleteFile(str); j(context, str); } } private static void j(Context context, String str) { synchronized (q) { SharedPreferences c2 = c(context); c2.edit().putString("uploadList", c2.getString("uploadList", "").replace(String.valueOf(str) + "|", "")).commit(); } } private static boolean j(Context context) { boolean z = true; C0257c.a("MobileAgentRun", "run into sessionpolicy"); String h2 = C0262h.h(context); SharedPreferences l2 = l(context); String string = l2.getString("sessionId", null); if (a(l2)) { if (string != null) { a(context, l2, true); SharedPreferences.Editor edit = l2.edit(); Long valueOf = Long.valueOf(l2.getLong("readFlowRev", 0)); Long valueOf2 = Long.valueOf(l2.getLong("readFlowSnd", 0)); edit.clear(); edit.putLong("readFlowRev", valueOf.longValue()).commit(); edit.putLong("readFlowSnd", valueOf2.longValue()).commit(); } a(context, h2, l2); a(context, l2, false); if (a(context, 1)) { e(context); } } else { String string2 = l2.getString("activities", null); SharedPreferences.Editor edit2 = l2.edit(); edit2.putString("activities", i(context, "onResume", string2)); edit2.putLong("lastResumeTime", System.currentTimeMillis()); edit2.commit(); if (g == 1 || string2.getBytes().length > 10000) { a(context, l2, false); } z = false; } C0257c.a("MobileAgentRun", "run out sessionpolicy"); return z; } private static SharedPreferences k(Context context) { return context.getSharedPreferences(String.valueOf(b) + "MoblieAgent_config_" + context.getPackageName(), 0); } private static SharedPreferences l(Context context) { return context.getSharedPreferences(String.valueOf(b) + "MoblieAgent_state_" + context.getPackageName(), 0); } private static synchronized long m(Context context) { long j2; synchronized (C0256b.class) { j2 = c(context).getLong("uploadpopindex", 0); } return j2; } private static String n(Context context) { String str; synchronized (q) { str = ""; String string = c(context).getString("uploadList", ""); if (!string.equals("")) { str = string.substring(0, string.indexOf("|")); } } return str; } private static boolean o(Context context) { NetworkInfo activeNetworkInfo = ((ConnectivityManager) context.getSystemService("connectivity")).getActiveNetworkInfo(); return activeNetworkInfo != null && activeNetworkInfo.getType() == 1; } }